package com.Students.controller;

import com.Students.pojo.Student;
import com.Students.service.IStudentService;
import com.Students.service.impl.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddStudentServlet")
public class AddStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String stu_id = request.getParameter("stu_id");
        String stu_name = request.getParameter("stu_name");
        String stu_clazz = request.getParameter("stu_clazz");
        String stu_phone = request.getParameter("stu_phone");
        Student student = new Student();
        student.setStu_ID(stu_id);
        student.setStu_name(stu_name);
        student.setStu_clazz(stu_clazz);
        student.setStu_phone(stu_phone);
        IStudentService service=new StudentService();
        service.add(student);
        response.sendRedirect("Students/add.jsp");
    }
}
